#!/usr/bin/env python
# -*- coding:utf-8 -*-


from scrapy.contrib.downloadermiddleware.useragent import \
UserAgentMiddleware
from bilibili.middlewares.resource import user_agent_list
import random


class RandomUserAgent(UserAgentMiddleware):
    def process_request(self, request, spider):
        ua = random.choice(user_agent_list)
        request.headers.setdefault('User-Agent', ua)
